package com.myapp.mobilesafe.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import com.myapp.mobilesafe.utils.PrefUtils;
import com.myapp.mobilesafe.utils.SuperAdmin;

public class SetupDirect04Activity extends BaseSetupActivity {
    private CheckBox protCheckbox;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup_direct04);
        protCheckbox = (CheckBox) findViewById(R.id.protect_checkbox);
        Boolean isChecked = PrefUtils.getBoolean("protect", false, this);
        if(isChecked){
            protCheckbox.setChecked(true);
            protCheckbox.setText("防盗服务已开启");
        }else {
            protCheckbox.setChecked(false);
            protCheckbox.setText("防盗服务已关闭");
        }
        protCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    protCheckbox.setText("防盗服务已开启");
                    PrefUtils.putBoolean("protect",true,getApplicationContext());
                }else {
                    protCheckbox.setText("防盗服务已关闭");
                    PrefUtils.putBoolean("protect", false, getApplicationContext());
                }
            }
        });
    }
    @Override
    public void goBack(){
        startActivity(new Intent(this,SetupDirect03Activity.class));
        finish();
        overridePendingTransition(R.anim.anim_back_in, R.anim.anim_back_out);
    }
    @Override
    public void goNext(){
        PrefUtils.putBoolean("configed", true, this);
        SuperAdmin.init(this);
        if(SuperAdmin.isActived()){
            startActivity(new Intent(this, SafeLocationActivity.class));
            finish();
            overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
        }else {
            Toast.makeText(this,"请先激活超级管理员",Toast.LENGTH_SHORT).show();
            SuperAdmin.activeAdmin();
        }

    }
}
